﻿using AiXiu.BLL;
using AiXiu.IBLL;
using System;
using System.Web;

namespace AiXiu.WebSite
{
    /// <summary>
    /// 视频点赞一般处理程序
    /// </summary>
    public class VideoLikeHandler : IHttpHandler
    {
        /// <summary>
        /// 处理请求
        /// </summary>
        /// <param name="context"></param>
        public void ProcessRequest(HttpContext context)
        {
            string videoId = context.Request.QueryString["videoId"];
            string userIdStr= context.Request.QueryString["userId"];
            if(!string.IsNullOrEmpty(videoId)&& !string.IsNullOrEmpty(userIdStr))
            {
                ILikeManager likeManager = new LikeManager();
                int userId = int.Parse(userIdStr);
                if (likeManager.IsLike(videoId, userId))
                {
                    likeManager.RemoveLike(videoId,userId);
                }
                else
                {
                    likeManager.AddLike(videoId, userId);
                }
            }

            // 输出结果
            context.Response.ContentType = "text/plain";
            context.Response.Write("ok");
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}